home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / 93win / data1.cab / Basic_Plus_Examples / PASSWORD < prev    next >
Encoding:
Text File  |  2005-03-02  |  8.4 KB  |  247 lines

  1. 10    ! ***********************************************************
  2. 20    ! Example: Passwords
  3. 30    !
  4. 40    ! This program demonstrates the operation of the STRING input widget
  5. 50    ! by creating a password panel that prompts the user for a name and
  6. 60    ! password. The program asks you for a name and password before it
  7. 70    ! brings up the panel.
  8. 80    !
  9. 90    ! ************************************************************
  10. 100   !
  11. 110  CLEAR SCREEN
  12. 120  OPTION BASE 1
  13. 130   !
  14. 140   ! Goodname is a flag that says a valid name has been obtained and
  15. 150   ! a password should be input. Done indicates a valid name and
  16. 160   ! password have been input.
  17. 170   !
  18. 180  INTEGER Goodname,Done
  19. 190  Goodname=0
  20. 200  Done=0
  21. 210   !
  22. 220   ! Strings Used:
  23. 230   !
  24. 240   ! Name$:   Stores user name for matching later
  25. 250   ! Pass$:   Stores user password for matching later
  26. 260   ! Inval$:  Input value from STRING widgets
  27. 270   ! B$:      General-purpose buffer
  28. 280   !
  29. 290  DIM Name$[80],Pass$[80],Inval$[80],B$[80]
  30. 300   !
  31. 310   ! Get name and password
  32. 320   !
  33. 330  INPUT "Please Input Your Name:",Name$
  34. 340  INPUT "Please Input a Password:",Pass$
  35. 350   !
  36. 360  DISP "Building Panel, Please Wait"
  37. 370   !
  38. 380   ! Define colors
  39. 390   !
  40. 400  INTEGER Black,White,Red,Blue
  41. 410  Black=0
  42. 420  White=1
  43. 430  Red=2
  44. 440  Blue=6
  45. 450   !
  46. 460   ! Get display dimensions
  47. 470   !
  48. 480  INTEGER A(6),Nlines
  49. 490  REAL Dw,Dh,Vh
  50. 500  GESCAPE CRT,3;A(*)       ! Get screen size
  51. 510  Dw=A(3)-A(1)+1
  52. 520  Dh=A(4)-A(2)+1
  53. 530  STATUS CRT,13;Nlines     ! Get number of lines of text on display
  54. 540  Vh=Dh*(1-6/Nlines)       ! Height of display above DISP line
  55. 550 !
  56. 560  REAL Px,Py,Pw,Ph,Ih,Iw
  57. 570  Pw=330                   ! Main PANEL width
  58. 580  Ph=260                   ! Main PANEL height
  59. 590  Px=(Dw-Pw)/2             ! Center PANEL along width
  60. 600  Py=(Vh-Ph)/2             ! Place above DISP line
  61. 610   !
  62. 620   ! Build main PANEL
  63. 630   !
  64. 640  ASSIGN @Main TO WIDGET "PANEL";SET ("VISIBLE":0)    ! Make invisible
  65. 650  CONTROL @Main;SET ("MAXIMIZABLE":0,"RESIZABLE":0)
  66. 660  CONTROL @Main;SET ("X":Px,"Y":Py,"WIDTH":Pw,"HEIGHT":Ph)
  67. 670  CONTROL @Main;SET ("TITLE":" Example: Passwords")
  68. 680  CONTROL @Main;SET ("SYSTEM MENU":"Quit")
  69. 690  ON EVENT @Main,"SYSTEM MENU" GOTO Finis
  70. 700   !
  71. 710   ! Get inside dimensions of PANEL
  72. 720   !
  73. 730  STATUS @Main;RETURN ("INSIDE WIDTH":Iw,"INSIDE HEIGHT":Ih)
  74. 740   !
  75. 750   ! Set up dimensions for widgets
  76. 760   !
  77. 770  REAL Gapw,Gaph,Wh,Ww1,Ww2
  78. 780  REAL R1,R2,R3,R4,R5,C1,C2
  79. 790   !
  80. 800   ! Set dimensions for interior widgets
  81. 810   !
  82. 820  Gapw=Iw*.02            ! Horizontal gap
  83. 830  Gaph=Ih*.02            ! Vertical gap
  84. 840   !
  85. 850  Wh=Ih*.16              ! Height of all child widgets
  86. 860  Ww1=Iw*.70             ! Width of STRING widgets and their LABELs
  87. 870  Ww2=Iw-Gapw*2          ! Width of prompt LABEL
  88. 880   !
  89. 890  R1=Gaph                ! Row position of LABEL for name-input STRING
  90. 900  R2=R1+Wh               ! Row position of name-input STRING
  91. 910  R3=R2+Wh+Gaph          ! Row position of LABEL for password-input STRING
  92. 920  R4=R3+Wh               ! Row position of password-input STRING
  93. 930  R5=R4+Wh               ! Bottom of password-input STRING
  94. 940  R6=((Ih-R5)-Wh)/2+R5   ! Row of prompt LABEL (centered at bottom)
  95. 950   !
  96. 960  C1=(Iw-Ww2)/2          ! Column position of prompt LABEL
  97. 970  C2=(Iw-Ww1)/2          ! Column position of STRINGs and their LABELs
  98. 980   !
  99. 990   ! Create LABEL for name-input STRING (no border, blends with PANEL)
  100. 1000  !
  101. 1010 ASSIGN @Lbl1 TO WIDGET "LABEL";PARENT @Main
  102. 1020 CONTROL @Lbl1;SET ("X":C2,"Y":R1,"WIDTH":Ww1,"HEIGHT":Wh)
  103. 1030 CONTROL @Lbl1;SET ("BORDER":0)
  104. 1040 CONTROL @Lbl1;SET ("FONT":"8 BY 16,BOLD")
  105. 1050 CONTROL @Lbl1;SET ("VALUE":" Enter your name:")
  106. 1060  !
  107. 1070  ! Create name-input STRING
  108. 1080  !
  109. 1090 ASSIGN @Str1 TO WIDGET "STRING";PARENT @Main
  110. 1100 CONTROL @Str1;SET ("X":C2,"Y":R2,"WIDTH":Ww1,"HEIGHT":Wh)
  111. 1110 CONTROL @Str1;SET ("BACKGROUND":Black,"PEN":Red)
  112. 1120 CONTROL @Str1;SET ("FONT":"8 BY 16")
  113. 1130 CONTROL @Str1;SET ("VALUE":"")
  114. 1140  !
  115. 1150  ! Create LABEL for password-input STRING
  116. 1160  !
  117. 1170 ASSIGN @Lbl2 TO WIDGET "LABEL";PARENT @Main
  118. 1180 CONTROL @Lbl2;SET ("X":C2,"Y":R3,"WIDTH":Ww1,"HEIGHT":Wh)
  119. 1190 CONTROL @Lbl2;SET ("BORDER":0)
  120. 1200 CONTROL @Lbl2;SET ("FONT":"8 BY 16,BOLD")
  121. 1210 CONTROL @Lbl2;SET ("VALUE":" Enter your password:")
  122. 1220  !
  123. 1230  ! Create STRING for password-input STRING. Both the background
  124. 1240  ! and font are black so the user cannot see what is typed in.
  125. 1250  ! A font type is not set, since it cannot be seen.
  126. 1260  !
  127. 1270 ASSIGN @Str2 TO WIDGET "STRING";PARENT @Main
  128. 1280 CONTROL @Str2;SET ("X":C2,"Y":R4,"WIDTH":Ww1,"HEIGHT":Wh)
  129. 1290 CONTROL @Str2;SET ("BACKGROUND":Black,"PEN":Red,"PASSWORD CHARACTER":"*")
  130. 1300 CONTROL @Str2;SET ("VALUE":"")
  131. 1310  !
  132. 1320  ! Create prompt LABEL
  133. 1330  !
  134. 1340 ASSIGN @Lbl3 TO WIDGET "LABEL";PARENT @Main
  135. 1350 CONTROL @Lbl3;SET ("X":C1,"Y":R6,"WIDTH":Ww2,"HEIGHT":Wh)
  136. 1360 CONTROL @Lbl3;SET ("FONT":"7 BY 14")
  137. 1370 CONTROL @Lbl3;SET ("BACKGROUND":Blue,"PEN":White)
  138. 1380 GOSUB Setprompt
  139. 1390  !
  140. 1400  ! Set up events. EVENTS are set up on the password STRING for both
  141. 1410  ! each KEYSTROKE and when Return is pressed, allowing a handler
  142. 1420  ! routine to generate a BEEP every time a key is pressed (for
  143. 1430  ! feedback, since you cannot see what you are typing) and allowing
  144. 1440  ! another handler routine to take the entire password when Return
  145. 1450  ! is pressed.
  146. 1460  !
  147. 1470 ON EVENT @Str1,"RETURN" GOSUB Getname
  148. 1480 ON EVENT @Str2,"RETURN" GOSUB Getpass
  149. 1490  !
  150. 1500 CLEAR SCREEN
  151. 1510 CONTROL @Main;SET ("VISIBLE":1)
  152. 1520  !
  153. 1530  ! Main loop, wait for event
  154. 1540  !
  155. 1550 LOOP
  156. 1560     IF Done=1 THEN Finis
  157. 1570 END LOOP
  158. 1580 !
  159. 1590 ! *********** End of Main Program *******************
  160. 1600 !
  161. 1610 ! This routine puts the standard prompt
  162. 1620 ! in the prompt LABEL
  163. 1630 !
  164. 1640 Setprompt: !
  165. 1650 B$="Please enter name, then password."
  166. 1660 GOSUB Setlabel
  167. 1670 RETURN
  168. 1680   !
  169. 1690   ! This routine puts a string passed to it through B$ in the
  170. 1700   ! prompt LABEL
  171. 1710   !
  172. 1720 Setlabel: !
  173. 1730 CONTROL @Lbl3;SET ("VALUE":B$)
  174. 1740 RETURN
  175. 1750   !
  176. 1760   ! This routine is invoked when Enter is pressed after inputting a
  177. 1770   ! name in the name-input STRING.  First, it tests to see if a name
  178. 1780   ! has already been input. If so, it outputs a message and exits.
  179. 1790   !
  180. 1800   ! Otherwise, it checks the input value for a match with the password.
  181. 1810   ! If it does not match, it gives a warning message and sets Goodname
  182. 1820   ! to 0.
  183. 1830   !
  184. 1840   ! If it does match, it changes the prompt to ask for a password only.
  185. 1850   ! In either case, it clears the STRING.
  186. 1860   !
  187. 1870 Getname: !
  188. 1880 DISABLE
  189. 1890 STATUS @Str1;RETURN ("VALUE":Inval$)
  190. 1900 IF Goodname=1 THEN
  191. 1910     BEEP 2000,.01
  192. 1920     B$="Please enter password"
  193. 1930     GOSUB Setlabel
  194. 1940 ELSE
  195. 1950     IF Inval$<>Name$ THEN
  196. 1960         BEEP 2000,.1
  197. 1970         B$="Invalid name"
  198. 1980         GOSUB Setlabel
  199. 1990         GOSUB Setprompt
  200. 2000         Goodname=0
  201. 2010     ELSE
  202. 2020         B$="Name accepted, please enter password."
  203. 2030         GOSUB Setlabel
  204. 2040         Goodname=1
  205. 2050     END IF
  206. 2060 END IF
  207. 2070 CONTROL @Str1;SET ("VALUE":"")
  208. 2080 ENABLE
  209. 2090 RETURN
  210. 2100   !
  211. 2110   ! This routine checks for a valid password. First, it checks
  212. 2120   ! to see if the user has provided a valid name. If not, it beeps
  213. 2130   ! and tells the user to input a valid name.
  214. 2140   !
  215. 2150   ! Otherwise, it tries to match the input string against the password.
  216. 2160   ! If no match, it tells the user and returns. If it matches, it also
  217. 2170   ! tells the user and sets a flag to tell the main routine it is done.
  218. 2180   !
  219. 2190 Getpass: !
  220. 2200 DISABLE
  221. 2210 IF Goodname=0 THEN
  222. 2220     BEEP 2000,.01
  223. 2230     B$="Please input your name first."
  224. 2240     GOSUB Setlabel
  225. 2250     WAIT 2
  226. 2260     GOSUB Setprompt
  227. 2270 ELSE
  228. 2280     STATUS @Str2;RETURN ("VALUE":Inval$)
  229. 2290     IF Inval$<>Pass$ THEN
  230. 2300         BEEP 2000,.01
  231. 2310         B$="Invalid password, try again."
  232. 2320         GOSUB Setlabel
  233. 2330         CONTROL @Str2;SET ("VALUE":"")
  234. 2340     ELSE
  235. 2350         B$="Welcome to the club!"
  236. 2360         GOSUB Setlabel
  237. 2370         WAIT 10
  238. 2380         Done=1
  239. 2390     END IF
  240. 2400 END IF
  241. 2410 ENABLE
  242. 2420 RETURN
  243. 2430   !
  244. 2440 Finis: !
  245. 2450 ASSIGN @Panel TO *    ! Delete PANEL widget
  246. 2460 END
  247.